package asionreachel.cn.smarthomedemo.data;

import java.util.ArrayList;

/**
 * Created by SuperMa on 2017/6/13.
 */

public class CDeviceTypeInfo {
    private String name;            //品种名
    private int icon;            //机器icon
    private String tag;             //设备标识
    ArrayList<CDeviceInfoData> deviceIdList = new ArrayList<CDeviceInfoData>();         //机器列表

    public void setDeviceInfo( String a_strName, int a_iIcon, String a_strTag )
    {
        name = a_strName;
        icon = a_iIcon;
        tag = a_strTag;
    }

    public String getName()
    {
        return name;
    }

    public int getIcon()
    {
        return icon;
    }

    public int getCount()
    {
        return deviceIdList.size();
    }

    public String getTag()
    {
        return tag;
    }

    public int getOnlineCount()
    {
        int count = 0;
        for (int i = 0; i < deviceIdList.size(); i++)
        {
            if (deviceIdList.get(i).getIsOnline())
                count++;
        }
        return count;
    }

    public String getCountInfo()
    {
        int onlineCount = getOnlineCount();
        int totalCount = getCount();
        return onlineCount + "/" + totalCount;
    }

    public CDeviceInfoData getDeviceInfoDataByIndex(int a_iIndex)
    {
        if (a_iIndex < deviceIdList.size())
            return deviceIdList.get(a_iIndex);
        return null;
    }

    //添加设备
    public void addDevice(String a_strDeviceId , boolean a_bOnline ,String a_strName)
    {
        deleteDevice( a_strDeviceId );
        CDeviceInfoData info = new CDeviceInfoData();
        info.setDeviceInfo(a_strDeviceId, a_strName, a_bOnline);
        deviceIdList.add(info);
    }

    //删除设备
    public void deleteDevice(String a_strDeviceId)
    {
        for (int i = 0; i < deviceIdList.size();i++)
        {
            if (deviceIdList.get(i).getDeviceId().equals( a_strDeviceId ))
                deviceIdList.remove(i);
        }
    }

    //清空设备
    public void clearDevice()
    {
        deviceIdList.clear();
    }

    public boolean IsDeviceIDExist( String a_strDeviceID )
    {
        for (int i = 0; i < deviceIdList.size();i++)
        {
            if( deviceIdList.get(i).getDeviceId().equals( a_strDeviceID ) )
                return true;
        }
        return false;
    }
}
